import { parseTextToRenderArray } from '@/TUIKit/components/TUIChat/emoji-config';

interface IMyConversationModel {
  conversationID: string
  customData: string
  draftText: string
  isMuted: boolean
  isPinned: boolean
  messageRemindType: string
  operationType: number
  remark: string
  subType: string
  type: string
  unreadCount: number
  avatar: string
  showName: string
  getAvatar(): string
  getShowName(): string
  getLastMessage(): string
}

class MyConversationModel implements IMyConversationModel {
  conversationID: string = ''
  customData: string = ''
  draftText: string = ''
  isMuted: boolean = false
  isPinned: boolean = false
  messageRemindType: string = ''
  operationType: number = 0
  remark: string = ''
  subType: string = ''
  type: string = ''
  unreadCount: number = 0
  avatar: string = ''
  showName: string = ''
  getAvatar() {
    return this.avatar
  }
  getShowName() {
    return this.showName
  }
  getLastMessage() {
    return ' '
  }
}

import TUIChatEngine from '@tencentcloud/chat-uikit-engine';

interface IMyMessageModel {
  avatar: string
  content: string
  createTime: string
  time: number
  flow: string
  id: string
  sendTime: string
  type: string
  reactionList: any[]
  readReceiptInfo: {}
  getMessageContent(): Record<string, any>
  initTime(): void
}

class MyMessageModel implements IMyMessageModel {
  avatar: string = ''
  content: string = ''
  createTime: string = ''
  time: number = 0
  flow: string = ''
  id: string = ''
  sendTime: string = ''
  type: string = ''
  reactionList: [] = []
  readReceiptInfo: {} = { isPeerRead: 0, readCount: 0, timestamp: 0, unreadCount: 0}
  getMessageContent() {
    if (this.type == TUIChatEngine.TYPES.MSG_TEXT) {
      let temp: any[] = parseTextToRenderArray(this.content)
      var renderArray: any[] = []
      for (let index = 0; index < temp.length; index++) {
        const element = temp[index];
        let item
        if (element.type == 'text') {
          item = { name: 'text', text: element.content}
        } else if (element.type == 'image') {
          item = { name: 'img', src: element.content, emojiKey: element.emojiKey}
        }
        renderArray.push(item)
      }

      let result: Record<string, any> = {
        // text: [{ name: 'text', text:  this.content}]
        text: renderArray
      }
      return result
    } else {
      let result: Record<string, any> = {
        // text: [{ name: 'text', text:  this.content}]
        url: this.content
      }
      return result
    }
  }
  initTime() {
    this.time = new Date(this.createTime).getTime() / 1000
  }
}

export { IMyConversationModel, MyConversationModel, MyMessageModel }